package com.offcn.listener;

import com.alibaba.otter.canal.protocol.CanalEntry;
import com.xpand.starter.canal.annotation.CanalEventListener;
import com.xpand.starter.canal.annotation.DeleteListenPoint;
import com.xpand.starter.canal.annotation.InsertListenPoint;
import com.xpand.starter.canal.annotation.UpdateListenPoint;

import java.util.function.Consumer;

/**
 * @Author: zola
 * @Date: 2021/9/10 - 09 - 10 - 22:29
 * @Description: com.offcn.listener
 * @Version: 1.0
 */
@CanalEventListener
public class CanalListener {
    // 监听添加
    @InsertListenPoint
    public void insertListener(CanalEntry.RowData rowData){
        rowData.getAfterColumnsList().forEach(new Consumer<CanalEntry.Column>() {
            @Override
            public void accept(CanalEntry.Column column) {
                System.out.println("新增的数据：" + column.getName() + ",新增的值：" + column.getValue());
            }
        });
    }


    @UpdateListenPoint
    public void updateListener(CanalEntry.RowData rowData){
        rowData.getAfterColumnsList().forEach(new Consumer<CanalEntry.Column>() {
            @Override
            public void accept(CanalEntry.Column column) {
                System.out.println("修改的数据：" + column.getName() + ",修改的值：" + column.getValue());
            }
        });
    }

    @DeleteListenPoint
    public void deleteListener(CanalEntry.RowData rowData){
        rowData.getAfterColumnsList().forEach(new Consumer<CanalEntry.Column>() {
            @Override
            public void accept(CanalEntry.Column column) {
                System.out.println("删除的数据：" + column.getName() + ",删除的值：" + column.getValue());
            }
        });
    }
}
